﻿using EPiAbstractions;
using EPiAbstractions.Opinionated;
using EPiMVC.Templates.Web.PageTypes;
using EPiServer;
using EPiServer.Core;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;

namespace EPiMVC.Templates.Web.Infrastructure
{
    public class StructureMapConfiguration : Registry
    {
        public StructureMapConfiguration()
        {
            Scan(AddInstancesUsingConventions);

            For<StartPage>().Use(GetStartPage);
        }

        private static StartPage GetStartPage()
        {
            return (StartPage) DataFactory.Instance.GetPage(PageReference.StartPage);
        }

        private static void AddInstancesUsingConventions(IAssemblyScanner scanner)
        {
            scanner.AssemblyContainingType<IDataFactoryFacade>();
            scanner.AssemblyContainingType<IPageRepository>();
            scanner.WithDefaultConventions();
        }
    }
}